package szzy

import (
	
	"github.com/flipped-aurora/gin-vue-admin/server/global"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
    "github.com/flipped-aurora/gin-vue-admin/server/model/szzy"
    szzyReq "github.com/flipped-aurora/gin-vue-admin/server/model/szzy/request"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
)

type StudentScoresApi struct {}



// CreateStudentScores 创建成绩模块
// @Tags StudentScores
// @Summary 创建成绩模块
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body szzy.StudentScores true "创建成绩模块"
// @Success 200 {object} response.Response{msg=string} "创建成功"
// @Router /CJ/createStudentScores [post]
func (CJApi *StudentScoresApi) CreateStudentScores(c *gin.Context) {
	var CJ szzy.StudentScores
	err := c.ShouldBindJSON(&CJ)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = CJService.CreateStudentScores(&CJ)
	if err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败:" + err.Error(), c)
		return
	}
    response.OkWithMessage("创建成功", c)
}

// DeleteStudentScores 删除成绩模块
// @Tags StudentScores
// @Summary 删除成绩模块
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body szzy.StudentScores true "删除成绩模块"
// @Success 200 {object} response.Response{msg=string} "删除成功"
// @Router /CJ/deleteStudentScores [delete]
func (CJApi *StudentScoresApi) DeleteStudentScores(c *gin.Context) {
	ID := c.Query("ID")
	err := CJService.DeleteStudentScores(ID)
	if err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("删除成功", c)
}

// DeleteStudentScoresByIds 批量删除成绩模块
// @Tags StudentScores
// @Summary 批量删除成绩模块
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
// @Router /CJ/deleteStudentScoresByIds [delete]
func (CJApi *StudentScoresApi) DeleteStudentScoresByIds(c *gin.Context) {
	IDs := c.QueryArray("IDs[]")
	err := CJService.DeleteStudentScoresByIds(IDs)
	if err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("批量删除成功", c)
}

// UpdateStudentScores 更新成绩模块
// @Tags StudentScores
// @Summary 更新成绩模块
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body szzy.StudentScores true "更新成绩模块"
// @Success 200 {object} response.Response{msg=string} "更新成功"
// @Router /CJ/updateStudentScores [put]
func (CJApi *StudentScoresApi) UpdateStudentScores(c *gin.Context) {
	var CJ szzy.StudentScores
	err := c.ShouldBindJSON(&CJ)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = CJService.UpdateStudentScores(CJ)
	if err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("更新成功", c)
}

// FindStudentScores 用id查询成绩模块
// @Tags StudentScores
// @Summary 用id查询成绩模块
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query szzy.StudentScores true "用id查询成绩模块"
// @Success 200 {object} response.Response{data=szzy.StudentScores,msg=string} "查询成功"
// @Router /CJ/findStudentScores [get]
func (CJApi *StudentScoresApi) FindStudentScores(c *gin.Context) {
	ID := c.Query("ID")
	reCJ, err := CJService.GetStudentScores(ID)
	if err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败:" + err.Error(), c)
		return
	}
	response.OkWithData(reCJ, c)
}

// GetStudentScoresList 分页获取成绩模块列表
// @Tags StudentScores
// @Summary 分页获取成绩模块列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query szzyReq.StudentScoresSearch true "分页获取成绩模块列表"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
// @Router /CJ/getStudentScoresList [get]
func (CJApi *StudentScoresApi) GetStudentScoresList(c *gin.Context) {
	var pageInfo szzyReq.StudentScoresSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	list, total, err := CJService.GetStudentScoresInfoList(pageInfo)
	if err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败:" + err.Error(), c)
        return
    }
    response.OkWithDetailed(response.PageResult{
        List:     list,
        Total:    total,
        Page:     pageInfo.Page,
        PageSize: pageInfo.PageSize,
    }, "获取成功", c)
}

// GetStudentScoresPublic 不需要鉴权的成绩模块接口
// @Tags StudentScores
// @Summary 不需要鉴权的成绩模块接口
// @accept application/json
// @Produce application/json
// @Param data query szzyReq.StudentScoresSearch true "分页获取成绩模块列表"
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
// @Router /CJ/getStudentScoresPublic [get]
func (CJApi *StudentScoresApi) GetStudentScoresPublic(c *gin.Context) {
    // 此接口不需要鉴权
    // 示例为返回了一个固定的消息接口，一般本接口用于C端服务，需要自己实现业务逻辑
    CJService.GetStudentScoresPublic()
    response.OkWithDetailed(gin.H{
       "info": "不需要鉴权的成绩模块接口信息",
    }, "获取成功", c)
}
